
import echarts from 'echarts';
// 引入柱状图
import 'echarts/lib/chart/bar';
// 引入提示框和标题组件
import 'echarts/lib/component/tooltip';
import 'echarts/lib/component/title';
import getStartEndDate from '../../core/util/getStartEndDate';

function statisticAnalyzeCtrl($scope, $http) {
  'ngInject';

  let _this = this;

  this.queryData = {};

  this.yearList = [{
    id:'01',
    year:'2015'
  },
  {
    id:'02',
    year:'2016'
  },]

  // 人员进出场情况汇总
  this.chartYearInit = () => {
    let option = {
      color: ['#59b0e7','#7cc78a','#a9a9a9'],
      title : {
        text: '人员进出场情况汇总',
        x: 'center',
        textStyle: {color: '#666'}
      },
      tooltip : {
        trigger: 'axis'
      },
      legend: {
        data: ['本月进场人数','本月离场人数','本月在线人数'],
        left: 20,
        top: 30
      },
      calculable: true,
      xAxis : [
        {
          type : 'category',
          data : ['1月','2月','3月','4月','5月','6月','7月','8月','9月','10月','11月','12月']
        }
      ],
      yAxis : [
        {
          show:false,
          type : 'value',
        }
      ],
      series : [
        {
          name:'本月进场人数',
          type:'bar',
          stack: '全部',
          barWidth : 30,
          itemStyle: {normal: {
            label : {show: true,
                    position:'top'
                  }
          }},
          data: _this.data4ChartShow.enterNum,
        },
        {
          name:'本月离场人数',
          type:'bar',
          stack: '全部',
          barWidth : 30,
          itemStyle: {normal: {
            label : {show: true,
                    position: 'bottom'
                  }
          }},
          data: _this.data4ChartShow.leaveNum,
        },
        {
          name:'本月在线人数',
          type:'line',
          label: {
                    normal: {
                      show: true,
                      position: 'top'
                    }
                  },
          data:_this.data4ChartShow.inNum,
        }
      ]
    };
    let myChart = echarts.init(document.getElementById('personnel-total'));
    myChart.setOption(option);
  }

  // 特种人员占比
  this.chartSpecialInit = () => {
  	let option = {
      tooltip : {
        trigger: 'item',
        formatter: "{a} <br/>{b} : {c} ({d}%)"
      },
		  title : {
		    text: '特种与非特种人员占比',
		    x: 'center',
		    textStyle: {color: '#666'}
		  },
		  color: ['#fe6f4d','#2de88e'],
		  legend: {
		    top: 40,
		    data: ['非特种人员','特种人员']
		  },
		  toolbox: {
		    show: true,
		    feature: {}
		  },
		  calculable: true,
		  series: [
		    {
		      name:'占比',
		      type: 'pie',
		      radius: ['35%', '55%'],
		      center: ['50%', '60%'],
		      data:[
		        {value:_this.data4ChartShow.specialTotal[0], name:_this.data4ChartShow.isSpecialMan[0] == '0' ? '非特种人员' : '特种人员'},
            {value:_this.data4ChartShow.specialTotal[1], name:_this.data4ChartShow.isSpecialMan[1] == '0' ? '非特种人员' : '特种人员'},
		      ],
          label : {
            normal : {
              show : true,
              position : 'outer',
              formatter : '{b}:{c}({d}%)'
            },
          },
		      itemStyle: {
		        emphasis: {
		          shadowBlur: 10,
		          shadowOffsetX: 0,
		          shadowColor: 'rgba(0, 0, 0, 0.5)'
		        }
		      }
		    }
		  ]
		};
		let myChart = echarts.init(document.getElementById('task-in-proportion'));
		myChart.setOption(option);
    myChart.on('click', (param) => {
      let isspecialMan = 1;
      if (param.componentType == 'series') {
        if (param.data.name == '非特种人员') {
          isspecialMan = 0;
        }
        $state.go('workerInfo',{isspecialMan: isspecialMan});
      }

    })
  }

  // 岗位占比
  this.chartCategoryInit = () => {
  	let option = {
		  tooltip : {
		    trigger: 'item',
		    formatter: "{a} <br/>{b} : {c} ({d}%)"
		  },
		  title : {
		    text: '岗位占比情况',
		    x:'center',
		    textStyle: {color: '#666'}
		  },
		  color: ['#fe6f4d', '#fdc638', '#2de88e', '#a8a8a8', '#44cede', '#299be4', '#5F6C75'],
		  legend: {
		    top:40,
		    data: _this.data4ChartShow.stationCategoryName
		  },
		  toolbox: {
		    show : true,
		    feature : {}
		  },
		  calculable : true,
		  series : [
		    {
		      name:'占比',
		      type: 'pie',
		      radius: ['35%', '55%'],
		      center: ['50%', '60%'],
		      data:[
		        {value:_this.data4ChartShow.categoryTotal[0], name:_this.data4ChartShow.stationCategoryName[0],stationCategory:_this.data4ChartShow.stationCategory[0]},
            {value:_this.data4ChartShow.categoryTotal[1], name:_this.data4ChartShow.stationCategoryName[1],stationCategory:_this.data4ChartShow.stationCategory[1]},
            {value:_this.data4ChartShow.categoryTotal[2], name:_this.data4ChartShow.stationCategoryName[2],stationCategory:_this.data4ChartShow.stationCategory[2]},
            {value:_this.data4ChartShow.categoryTotal[3], name:_this.data4ChartShow.stationCategoryName[3],stationCategory:_this.data4ChartShow.stationCategory[3]},
            {value:_this.data4ChartShow.categoryTotal[4], name:_this.data4ChartShow.stationCategoryName[4],stationCategory:_this.data4ChartShow.stationCategory[4]},
            {value:_this.data4ChartShow.categoryTotal[5], name:_this.data4ChartShow.stationCategoryName[5],stationCategory:_this.data4ChartShow.stationCategory[5]},
            {value:_this.data4ChartShow.categoryTotal[6], name:_this.data4ChartShow.stationCategoryName[6],stationCategory:_this.data4ChartShow.stationCategory[6]},
		      ],
          label : {
            normal : {
              show : true,
              position : 'outer',
              formatter : '{b}:{c}({d}%)'
            },
          },
		      itemStyle: {
		        emphasis: {
		          shadowBlur: 10,
		          shadowOffsetX: 0,
		          shadowColor: 'rgba(0, 0, 0, 0.5)'
		        }
		      }
		    }
		  ]
		};
		let myChart = echarts.init(document.getElementById('task-in-proportion1'));
		myChart.setOption(option);
    myChart.on('click', (param) => {
      if (param.componentType == 'series') {
        $state.go('workerInfo',{stationCategory: param.data.stationCategory,stationCategoryText: param.data.name});
      }

    })
  }

  // 设备
  // 机械设备进出场情况汇总
  this.chartMonthInit = () => {
    let option = {
      color: ['#59b0e7','#7cc78a','#a9a9a9'],
      title : {
        text: '机械设备进出场情况汇总',
        x:'center',
        textStyle: {color: '#666'}
      },
      tooltip : {
        trigger: 'axis'
      },
      legend: {
        data:['本月进场设备数','本月离场设备数','本月在线设备数'],
        left:20,
        top:30
      },
      calculable: true,
      xAxis : [
        {
          type : 'category',
          data : ['1月','2月','3月','4月','5月','6月','7月','8月','9月','10月','11月','12月']
        }
      ],
      yAxis : [
        {
          show:false,
          type : 'value',
        }
      ],
      series : [
        {
          name:'本月进场设备数',
          type:'bar',
          stack: '全部',
          barWidth : 30,
          itemStyle: {normal: {
            label : {show: true,
              position:'top'}
          }},
          data: _this.dataDeviceChartShow.countInto
        },
        {
          name:'本月离场设备数',
          type:'bar',
          stack: '全部',
          barWidth : 30,
          itemStyle: {normal: {
            label : {
              show: true,
              position: 'bottom'
            }
          }},
          data: _this.dataDeviceChartShow.countOut
        },
        {
          name:'本月在线设备数',
          type:'line',
          label: {
                    normal: {
                      show: true,
                      position: 'top'
                    }
                  },
          data: _this.dataDeviceChartShow.countIn
        }
      ]
    };
    let myChart = echarts.init(document.getElementById('mechanical-equipment-total'));
    myChart.setOption(option);
  }

  // 设备类型等级占比
  this.chartShebeiInit = () => {
  	let option = {
		  tooltip : {
		    trigger: 'item',
		    formatter: "{a} <br/>{b} : {c} ({d}%)"
		  },
		  title : {
		    text: '设备类型占比情况',
		    x:'center',
		    textStyle: {color: '#666'}
		  },
		  color: ['#fe6f4d', '#fdc638', '#2de88e'],
		  legend: {
		    top:40,
		    data: ['一般设备','主要设备','特种设备']
		  },
		  toolbox: {
		    show : true,
		    feature : {}
		  },
		  calculable : true,
		  series : [
		    {
		      name:'占比',
		      type: 'pie',
		      radius: ['35%', '55%'],
		      center: ['50%', '60%'],
		      data:[
		        {value:this.dataDeviceChartShow.deviceLevelTotal[0],
              name:this.dataDeviceChartShow.deviceLevel[0] == '1' ? '一般设备' :
              this.dataDeviceChartShow.deviceLevel[0] == '2' ? '主要设备' :
              this.dataDeviceChartShow.deviceLevel[0] == '3' ? '关键设备 ' :
              this.dataDeviceChartShow.deviceLevel[0] == '4' ? '特种设备' : ''},
		        {value:this.dataDeviceChartShow.deviceLevelTotal[1],
              name:this.dataDeviceChartShow.deviceLevel[1] == '1' ? '一般设备' :
              this.dataDeviceChartShow.deviceLevel[1] == '2' ? '主要设备' :
              this.dataDeviceChartShow.deviceLevel[1] == '3' ? '关键设备 ' :
              this.dataDeviceChartShow.deviceLevel[1] == '4' ? '特种设备' : ''},
		        {value:this.dataDeviceChartShow.deviceLevelTotal[2],
              name:this.dataDeviceChartShow.deviceLevel[2] == '1' ? '一般设备' :
              this.dataDeviceChartShow.deviceLevel[2] == '2' ? '主要设备' :
              this.dataDeviceChartShow.deviceLevel[2] == '3' ? '关键设备 ' :
              this.dataDeviceChartShow.deviceLevel[2] == '4' ? '特种设备' : ''},
		      ],
          label : {
            normal : {
              show : true,
              position : 'outer',
              formatter : '{b}:{c}({d}%)'
            },
          },
		      itemStyle: {
		        emphasis: {
		          shadowBlur: 10,
		          shadowOffsetX: 0,
		          shadowColor: 'rgba(0, 0, 0, 0.5)'
		        }
		      }
		    }
		  ]
		};
		let myChart = echarts.init(document.getElementById('task-in-proportion2'));
		myChart.setOption(option);
    myChart.on('click', (param) => {
      const equipCategoryMap = {
        '一般设备': 1,
        '主要设备': 2,
        '特种设备': 4,
      }
      if (param.componentType == 'series') {
        $state.go('equipmentInfo',{deviceLevel: equipCategoryMap[param.data.name]});
      }

    })
  }

  // 设备检验情况
  this.chartShebeiInfoInit = () => {
  	let option = {
		  tooltip : {
		    trigger: 'item',
		    formatter: "{a} <br/>{b} : {c} ({d}%)"
		  },
		  title : {
		    text: '设备检验情况',
		    x:'center',
		    textStyle: {color: '#666'}
		  },
		  color: ['#fe6f4d', '#fdc638'],
		  legend: {
		    top: 40,
		    data: ['检验','未检验']
		  },
		  toolbox: {
		    show: true,
		    feature: {}
		  },
		  calculable: true,
		  series: [
		    {
		      name:'占比',
		      type: 'pie',
		      radius: ['35%', '55%'],
		      center: ['50%', '60%'],
		      data:[
		        {value:this.dataDeviceChartShow.num[0],
              name:this.dataDeviceChartShow.holderStatus[0] == '0' ? '未检验' :
                this.dataDeviceChartShow.holderStatus[0] == '1' ? '检验' : ''},
		        {value:this.dataDeviceChartShow.num[1],
              name:this.dataDeviceChartShow.holderStatus[1] == '0' ? '未检验' :
                this.dataDeviceChartShow.holderStatus[1] == '1' ? '检验' : ''},
		      ],
          label : {
            normal : {
              show : true,
              position : 'outer',
              formatter : '{b}:{c}({d}%)'
            },
          },
		      itemStyle: {
		        emphasis: {
		          shadowBlur: 10,
		          shadowOffsetX: 0,
		          shadowColor: 'rgba(0, 0, 0, 0.5)'
		        }
		      }
		    }
		  ]
		};
		let myChart = echarts.init(document.getElementById('task-in-proportion3'));
		myChart.setOption(option);
    myChart.on('click', (param) => {
      const equipHolderStatus = {
        '未检验': 0,
        '检验': 1,
      }
      if (param.componentType == 'series') {
        $state.go('equipmentInfo',{inspectionRecords : equipHolderStatus[param.data.name]});
      }

    })
  }


  // 20160918 yuxt test
  this.chartkaoheInit = () => {
    let option = {
      color: ['#6dcbe4'],
      tooltip : {
        trigger: 'axis'
      },
      legend: {
        left:20,
        top:0,
        data:['巡查问题月度环比']
      },
      toolbox: {
        show : true,
        feature : {}
      },
      calculable : true,
      xAxis : [
        {
          type : 'category',
          data : this.checkMonthDataX,
        }
      ],
      yAxis : [
        {
          type : 'value',
        }
      ],
      series : [
        {
          name:'数量',
          type:'bar',
          data: this.checkMonthDataY,
          barWidth : 30,
          label: {
            normal: {
              show: true,
              position: 'top',
            }
          },
        }
      ]
    };
		let myChart = echarts.init(document.getElementById('task-in-proportion4'));
		myChart.setOption(option);
    myChart.on('click', (param) => {
      if (param.componentType == 'series') {
        var res = [];
        if (param.name.length && param.name.length == 2) {
          res.push(param.name.substr(0,1)-1);
        } else if (param.name.length && param.name.length == 3) {
          res.push(param.name.substr(0,2)-1);
        }
        let startEndDate = getStartEndDate(_this.years, res);
        $state.go('inspectContent',{problemFoundTimeFrom: startEndDate.startDateStr, problemFoundTimeTo: startEndDate.endDateStr, checkResult: 0,type: 'filter'});
      } else if (param.componentType == 'markPoint') {

      }


    })
  }

  //   this.chartkaoheInit = () => {
  //   let option = {
  //     tooltip : {
  //       trigger: 'item',
  //       formatter: "{a} <br/>{b} : {c} ({d}%)"
  //     },
  //     title : {
  //       text: '巡查来源占比情况',
  //       x:'center',
  //       textStyle: {color: '#666'}
  //     },
  //     color: ['#fe6f4d', '#fdc638'],
  //     legend: {
  //       top: 40,
  //       data: ['平安考核','日常巡查']
  //     },
  //     toolbox: {
  //       show : true,
  //       feature : {}
  //     },
  //     calculable : true,
  //     series : [
  //       {
  //         name:'得分占比',
  //         type: 'pie',
  //         radius: ['35%', '55%'],
  //         center: ['50%', '60%'],
  //         data:[
  //           {value:_this.dataCheckChartShow.kaoHeNum[0],
  //             name:_this.dataCheckChartShow.taskType[0] == '0' ? '平安考核' :
  //             _this.dataCheckChartShow.taskType[0] == '1' ? '日常巡查' : ''},
  //           {value:_this.dataCheckChartShow.kaoHeNum[1],
  //             name:_this.dataCheckChartShow.taskType[1] == '0' ? '平安考核' :
  //             _this.dataCheckChartShow.taskType[1] == '1' ? '日常巡查' : ''},
  //         ],
  //         itemStyle: {
  //           emphasis: {
  //             shadowBlur: 10,
  //             shadowOffsetX: 0,
  //             shadowColor: 'rgba(0, 0, 0, 0.5)'
  //           }
  //         }
  //       }
  //     ]
  //   };
  //   let myChart = echarts.init(document.getElementById('task-in-proportion4'));
  //   myChart.setOption(option);
  // }

  // 问题分类
  this.chartProblemInit = () => {
  	let option = {
		  tooltip : {
		    trigger : 'item',
		    formatter : "{a} <br/>{b} : {c} ({d}%)"
		  },
		  title : {
		    text : '巡查分类情况',
		    x : 'center',
		    textStyle : {color: '#666'}
		  },
		  color : ['#fe6f4d', '#fdc638', '#2de88e', '#a8a8a8', '#44cede', '#299be4', '#5F6C75'],
		  legend : {
		    top :40,
		    data : _this.dataCheckChartShow.checkCategoryName
		  },
		  toolbox : {
		    show : true,
		    feature : {}
		  },
		  calculable : true,
		  series : [
		    {
		      name :'占比',
		      type : 'pie',
		      radius : ['35%', '55%'],
		      center : ['50%', '60%'],
		      data : [
		        {value : _this.dataCheckChartShow.problemNum[0], name : _this.dataCheckChartShow.checkCategoryName[0],checkClassifyId : _this.dataCheckChartShow.checkClassifyId[0]},
            {value : _this.dataCheckChartShow.problemNum[1], name : _this.dataCheckChartShow.checkCategoryName[1],checkClassifyId : _this.dataCheckChartShow.checkClassifyId[1]},
            {value : _this.dataCheckChartShow.problemNum[2], name : _this.dataCheckChartShow.checkCategoryName[2],checkClassifyId : _this.dataCheckChartShow.checkClassifyId[2]},
            {value : _this.dataCheckChartShow.problemNum[3], name : _this.dataCheckChartShow.checkCategoryName[3],checkClassifyId : _this.dataCheckChartShow.checkClassifyId[3]},
            {value : _this.dataCheckChartShow.problemNum[4], name : _this.dataCheckChartShow.checkCategoryName[4],checkClassifyId : _this.dataCheckChartShow.checkClassifyId[4]},
            {value : _this.dataCheckChartShow.problemNum[5], name : _this.dataCheckChartShow.checkCategoryName[5],checkClassifyId : _this.dataCheckChartShow.checkClassifyId[5]},
            {value : _this.dataCheckChartShow.problemNum[6], name : _this.dataCheckChartShow.checkCategoryName[6],checkClassifyId : _this.dataCheckChartShow.checkClassifyId[6]},
		      ],
          label: {
            normal: {
                show: true,
                position: 'outer',
                formatter: '{b}:{c}({d}%)'
            },
          },
		      itemStyle: {
		        emphasis: {
		          shadowBlur: 10,
		          shadowOffsetX: 0,
		          shadowColor: 'rgba(0, 0, 0, 0.5)'
		        }
		      }
		    }
		  ]
		};
		let myChart = echarts.init(document.getElementById('task-in-proportion5'));
		myChart.setOption(option);
    myChart.on('click',function(param){
      if (param.componentType == 'series') {
        $state.go('inspectContent',{checkClassifyId: param.data.checkClassifyId, checkClassifyName: param.data.name, checkResult: 0, type: 'filter'});
      }
    })
  }

  // 原因分析
  this.chartReasonInit = () => {
  	let option = {
		  tooltip : {
		    trigger : 'item',
		    formatter : "{a} <br/>{b} : {c} ({d}%)"
		  },
		  title : {
		    text : '原因分析情况',
		    x : 'center',
		    textStyle : {color: '#666'}
		  },
		  color: ['#fe6f4d', '#fdc638', '#a8a8a8', '#2de88e', '#44cede', '#299be4','#5F6C75'],
		  legend : {
		    top : 40,
        left : 5,
		    data : _this.dataCheckChartShow.causeName
		  },
		  toolbox: {
		    show : true,
		    feature : {}
		  },
		  calculable : true,
		  series : [
		    {
		      name :'占比',
		      type : 'pie',
		      radius : ['35%', '55%'],
		      center : ['50%', '60%'],
		      data : [
		        {value : _this.dataCheckChartShow.causeNum[0], name : _this.dataCheckChartShow.causeName[0]},
            {value : _this.dataCheckChartShow.causeNum[1], name : _this.dataCheckChartShow.causeName[1]},
            {value : _this.dataCheckChartShow.causeNum[2], name : _this.dataCheckChartShow.causeName[2]},
            {value : _this.dataCheckChartShow.causeNum[3], name : _this.dataCheckChartShow.causeName[3]},
            {value : _this.dataCheckChartShow.causeNum[4], name : _this.dataCheckChartShow.causeName[4]},
            {value : _this.dataCheckChartShow.causeNum[5], name : _this.dataCheckChartShow.causeName[5]},
		      ],
          label : {
            normal : {
                show : true,
                position : 'outer',
                formatter : '{b}:{c}({d}%)'
            },
          },
		      itemStyle : {
		        emphasis : {
		          shadowBlur : 10,
		          shadowOffsetX : 0,
		          shadowColor : 'rgba(0, 0, 0, 0.5)'
		        }
		      }
		    }
		  ]
		};
		let myChart = echarts.init(document.getElementById('task-in-proportion6'));
		myChart.setOption(option);
    myChart.on('click', (param) => {
      if (param.componentType == 'series') {
        $state.go('inspectContent',{causeAnalysis: param.data.name});
      }
    });
  }

  // 安全员今日巡查情况
  this.chartXunChaInit = () => {
    let option = {
      color : ['#6dcbe4'],
      tooltip : {
        trigger : 'axis'
      },
      legend : {
        left : 20,
        top : 0,
        data : ['安全员今日巡查情况']
      },
      toolbox : {
        show : true,
        feature : {}
      },
      calculable : true,
      xAxis : [
        {
          type : 'category',
          splitLine : {
            show: false
          },
          data : _this.dataCheckChartShow.userName,
          axisLabel : {
            interval : 0,
          }
        }
      ],
      yAxis : [
        {
          type : 'value',
          minInterval : 1,
        }
      ],
      series : [
        {
          name : '次数',
          type : 'bar',
          data :  _this.dataCheckChartShow.xunChaNum,
          label: {
            normal: {
              show: true,
              position: 'top',
            }
          },
          barWidth : 30,
        }
      ]
    };
    let myChart = echarts.init(document.getElementById('maintenance-condition1'));
    myChart.setOption(option);
    myChart.on('click', (param) => {
      if (param.componentType == 'series') {
        $state.go('dailyCheck',{createUserName: param.name,checkCompletedTimeFrom: _this.days});
      }
    });

  }

  // 本周标段巡查情况
  this.chartWeekInit = () => {
    let option = {
      color : ['#6dcbe4'],
      tooltip : {
        trigger : 'axis'
      },
      legend : {
        left : 20,
        top : 0,
        data : ['本周标段巡查情况']
      },
      toolbox : {
        show : true,
        feature : {}
      },
      calculable : true,
      xAxis : [
        {
          type : 'category',
          data : _this.dataCheckChartShow.createDate
        }
      ],
      yAxis : [
        {
          type : 'value',
        }
      ],
      series : [
        {
          name : '次数',
          type : 'bar',
          data :  _this.dataCheckChartShow.weekNum,
          label: {
            normal: {
              show: true,
              position: 'top',
            }
          },
          barWidth : 30,
        }
      ]
    };
    let myChart = echarts.init(document.getElementById('maintenance-condition2'));
    myChart.setOption(option);
    myChart.on('click', (param) => {
      if (param.componentType == 'series') {
        let dateArray = param.name.replace(/日/g, '').split('月');
        let resString = `${new Date().getFullYear()}-${dateArray[0]}-${dateArray[1]}`;
        $state.go('dailyCheck',{startDateFrom : resString, startDateTo : resString});
      }

    })
  }

  // 日期格式化
  Date.prototype.Format = function(fmt)
  { //author: meizz
    var o = {
      "M+" : this.getMonth()+1,                 //月份
      "d+" : this.getDate(),                    //日
    };
    if(/(y+)/.test(fmt))
      fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));
    for(var k in o)
      if(new RegExp("("+ k +")").test(fmt))
    fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
    return fmt;
  }

  var myDate = new Date();
  _this.years = myDate.getFullYear();
  _this.days = myDate.Format('yyyy-MM-dd');

  this.listData = {};
  // 获取人员进出场情况
  this.getWorker = () => {

    //test以下内容为测试内容
    // if(this.queryData.bidId == "5BED013543A245028CFFC00A19B02133"){
    //   this.checkMonthData = [0,30,0,0,0,0];
    // }else{
    //   this.checkMonthData = [0,68,13,0,0,0];
    // }

    let respData = {
      date: _this.years,
    }

    let deviceData = {
      year: _this.years,
    }

    let checkData = {
      taskType: '1',
      createTime: _this.days,
      day: '7'
    }

    // 人员
    $http.post(`${SERVER_CONTEXT}/api/statistic/workerAllStatistics`,
        angular.extend(this.queryData, respData)
            )
          .then((resp) => {
            if (resp.data.success) {
              // 人员年度统计
              this.listWorker = [];
              for(key in resp.data.data.workerAccessStatistic){
                this.listWorker.push(resp.data.data.workerAccessStatistic[key]);
              }
              this.listData.enterNum = [];
              this.listData.inNum = [];
              this.listData.leaveNum = [];
              this.listWorker.forEach((item) => {
                 this.listData.enterNum.push(item.enterNum);
                 this.listData.inNum.push(item.inNum);
                 this.listData.leaveNum.push(item.leaveNum);
              });

              // 统计特种非特种人员
              this.listSpecial = [];
              for(key in resp.data.data.specialStatistics){
                this.listSpecial.push(resp.data.data.specialStatistics[key]);
              }
              this.listData.specialTotal = [];
              this.listData.isSpecialMan = [];
              this.listSpecial.forEach((item) => {
                 this.listData.specialTotal.push(item.total);
                 this.listData.isSpecialMan.push(item.isSpecialMan);
              })

              // 岗位占比 （处理其他数据）
              this.listStation = [];
              for(key in resp.data.data.stationStatistics){
                this.listStation.push(resp.data.data.stationStatistics[key]);
              }
              this.listData.categoryTotal = [];
              this.listData.stationCategoryName = [];
              this.listData.stationCategory = [];
              this.listStation.forEach((item) => {
                this.listData.categoryTotal.push(item.total);
                this.listData.stationCategoryName.push(item.stationCategoryName);
                this.listData.stationCategory.push(item.stationCategory);
              })

              this.categoryTotal = this.listData.categoryTotal.slice(0,6);
              this.listStationElse = this.listData.categoryTotal.slice(6);
              this.stationCategoryName = this.listData.stationCategoryName.slice(0,6);
              this.stationCategoryName.push('其他');
              this.stationCategory = this.listData.stationCategory.slice(0,6);
              this.stationCategory.push(this.stationCategory.toString());
              var resultStation = 0;
              for(var i=0;i<this.listStationElse.length;i++){
                resultStation +=this.listStationElse[i];
              }
              this.categoryTotal.push(resultStation);
              this.data4ChartShow = {
                "enterNum": this.listData.enterNum, //进场在场离场
                "inNum": this.listData.inNum,
                "leaveNum": this.listData.leaveNum,
                "specialTotal": this.listData.specialTotal, // 特种非特种
                "isSpecialMan": this.listData.isSpecialMan,
                "categoryTotal": this.categoryTotal,  // 岗位占比
                "stationCategoryName": this.stationCategoryName,
                "stationCategory": this.stationCategory,
              }

              this.chartYearInit(); // 人员年统计echart

              this.chartSpecialInit();  // 特种与非特种占比 echarts

              this.chartCategoryInit(); // 岗位占比 echarts

            }

          })

    // 设备
    $http.post(`${SERVER_CONTEXT}/api/statistic/deviceAllStatistics`,
      angular.extend(this.queryData, deviceData)
            )
            .then((resp) => {
              if (resp.data.success) {
                // 设备年度统计
                this.listDrive = [];
                for(key in resp.data.data.driveStatistics){
                  this.listDrive.push(resp.data.data.driveStatistics[key]);
                }
                this.listData.countIn = [];
                this.listData.countOut = [];
                this.listData.countInto = [];
                this.listDrive.forEach((item) => {
                   this.listData.countIn.push(item.countIn);
                   this.listData.countOut.push(item.countOut);
                   this.listData.countInto.push(item.countInto);
                });

                // 设备检验占比
                this.listDeviceHolder = [];
                for(key in resp.data.data.deviceHolderStatistics){
                  this.listDeviceHolder.push(resp.data.data.deviceHolderStatistics[key]);
                }
                this.listData.holderStatus = [];
                this.listData.num = [];
                this.listDeviceHolder.forEach((item) => {
                   this.listData.holderStatus.push(item.holderStatus);
                   this.listData.num.push(item.num);
                })

                // 设备等级统计
                this.listDeviceLevel = [];
                for(key in resp.data.data.deviceLevelStatistics){
                  this.listDeviceLevel.push(resp.data.data.deviceLevelStatistics[key]);
                }
                this.listData.deviceLevelTotal = [];
                this.listData.deviceLevel = [];
                this.listDeviceLevel.forEach((item) => {
                  this.listData.deviceLevelTotal.push(item.total);
                  this.listData.deviceLevel.push(item.deviceLevel);
                })

                this.dataDeviceChartShow = {
                  "countIn": this.listData.countIn,  // 进场在场离场
                  "countOut": this.listData.countOut,
                  "countInto": this.listData.countInto,
                  "holderStatus": this.listData.holderStatus, // 检验
                  "num": this.listData.num,
                  "deviceLevelTotal": this.listData.deviceLevelTotal, // 等级
                  "deviceLevel": this.listData.deviceLevel,
                }

                this.chartMonthInit(); // 设备年统计echart

                this.chartShebeiInit();  // 设备特征 echarts

                this.chartShebeiInfoInit(); // 设备检验 echarts
              }
            })

    // 巡查概况
    $http.post(`${SERVER_CONTEXT}/api/statistic/checkAllStatistics`,
      angular.extend(this.queryData,checkData)
            )
            .then((resp) => {
              if (resp.data.success) {
                //巡查问题月度环比
                this.checkMonthDataX = resp.data.data.problemNumStatistic.map(function(item){
                  return item.createDate;
                });
                this.checkMonthDataY = resp.data.data.problemNumStatistic.map(function(item){
                  return item.num;
                });

                // 来源占比
                // this.listKaoHe = [];
                // for(key in resp.data.data.checkSourceStatistic){
                //   this.listKaoHe.push(resp.data.data.checkSourceStatistic[key]);
                // }
                // this.listData.taskType = [];
                // this.listData.kaoHeNum = [];
                // this.listKaoHe.forEach((item) => {
                //    this.listData.taskType.push(item.taskType);
                //    this.listData.kaoHeNum.push(item.num);
                // });

                // 问题分类
                this.listProblem = [];
                for(key in resp.data.data.problemTypeStatistic){
                  this.listProblem.push(resp.data.data.problemTypeStatistic[key]);
                }
                this.listData.problemNum = [];
                this.listData.checkCategoryName = [];
                this.listData.checkClassifyId = [];
                this.otherCheckClassifyId = [];
                this.listProblem.forEach((item) => {
                   this.listData.problemNum.push(item.num);
                   this.listData.checkCategoryName.push(item.checkCategoryName);
                   this.listData.checkClassifyId.push(item.checkClassifyId);
                })

                this.problemNum = this.listData.problemNum.slice(0,6);
                this.listCheckElse = this.listData.problemNum.slice(6);
                this.checkCategoryName = this.listData.checkCategoryName.slice(0,6);
                this.checkClassifyId = this.listData.checkClassifyId.slice(0,6);
                this.checkCategoryName.push('其他');
                this.checkClassifyId.push(this.checkClassifyId.toString());
                var resultCheck = 0;
                for(var i=0;i<this.listCheckElse.length;i++){
                  resultCheck +=this.listCheckElse[i];
                }
                this.problemNum.push(resultCheck);

                // 本周标段
                this.listWeek = [];
                for(key in resp.data.data.cycleCheckStatistic){
                  this.listWeek.push(resp.data.data.cycleCheckStatistic[key]);
                }
                this.listData.weekNum = [];
                this.listData.createDate = [];
                this.listWeek.forEach((item) => {
                  this.listData.weekNum.push(item.num);
                  this.listData.createDate.push(item.createDate);
                })

                // 原因分析
                this.listData.causeName = [];
                this.listData.causeNum = [];
                for(key in resp.data.data.causeAnalysisStatistics){
                  this.listData.causeName.push(key);
                  this.listData.causeNum.push(resp.data.data.causeAnalysisStatistics[key]);
                }

                // 安全员今日巡查情况
                this.listXunCha = [];
                for(key in resp.data.data.checkStatistic){
                  this.listXunCha.push(resp.data.data.checkStatistic[key]);
                }
                this.listData.xunChaNum = [];
                this.listData.userName = [];
                this.listXunCha.forEach((item) => {
                  this.listData.xunChaNum.push(item.num);
                  this.listData.userName.push(item.userName);
                })

                this.dataCheckChartShow = {
                  "taskType": this.listData.taskType, // 来源
                  "kaoHeNum": this.listData.kaoHeNum,
                  "problemNum": this.problemNum,  // 问题分类
                  "checkCategoryName": this.checkCategoryName,
                  "checkClassifyId": this.checkClassifyId,
                  "weekNum": this.listData.weekNum, // 一周标段
                  "createDate": this.listData.createDate,
                  "causeName": this.listData.causeName, // 原因分析
                  "causeNum": this.listData.causeNum,
                  "xunChaNum": this.listData.xunChaNum, // 安全员今天巡查
                  "userName": this.listData.userName,
                }

                this.chartkaoheInit(); // 考核来源echart

                this.chartProblemInit();  // 问题分类 echarts

                this.chartWeekInit(); // 本周标段 echarts

                this.chartReasonInit(); // 原因分析 echarts

                this.chartXunChaInit(); // 安全员今日巡查情况

              }
            })


  }

  // 点击年
  this.syearOne = (param) => {
    _this.years = param.year;
    param.acitve = true;
    this.getWorker();
  }

  // visited样式判断
  this.isVisited = (item) => {
    let isVisited = false;
    if (item.year == _this.years) {
      isVisited = true;
    }
    return isVisited;
  }

  // 获取当前时间 下划线
  this.getDate = (param) => {
    // 当前时间
    this.yearList.forEach((item) => {
      if (item.year == _this.years) {
        item.active = true;
      }
    })
  }

  // 初始化页面
  this.initPage = () => {

    // 获取当前时间变色
    this.getDate();

  }

  this.initPage();

}

export default statisticAnalyzeCtrl;